<template>
  <div class="user-page">
    <el-card>
      <template #header>
        <div class="card-header">
          <span class="card-title">操作日志</span>
          <div class="conditions">
            <span>操作目标账号：</span>
            <el-select v-model="conditionState.userId" placeholder="请选择" clearable>
              <el-option v-for="user in userList" :key="user.userId" :value="user.userId" :label="user.userAccount">{{user.userAccount}}</el-option>
            </el-select>
            <span>操作类型：</span>
            <el-select v-model="conditionState.type" placeholder="请选择" clearable>
              <el-option value="recharge" label="充值">充值</el-option>
            </el-select>
            <el-button type="primary" @click="handleSearch">查询</el-button>
          </div>
        </div>
      </template>
      <el-table :data="logList" style="width: 100%">
        <el-table-column prop="userAccount" label="操作目标账号" width="180" >
          <template #default="scope">
            <span>{{scope.row.toUserInfo ? scope.row.toUserInfo.userAccount : ''}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="操作类型" width="160">
          <template #default="scope">
            <span v-if="scope.row.type === 'recharge'">充值</span>
          </template>
        </el-table-column>
        <el-table-column prop="desc" label="操作" />
        <el-table-column prop="time" label="操作时间"  width="200" />
      </el-table>
      <div class="pagination-box">
        <el-pagination layout="prev, pager, next" :total="conditionState.total" @current-change="handlePageChange"/>
      </div>
    </el-card>

  </div>
</template>

<script setup>
import {ref, nextTick} from 'vue'
import api from '../../api/index.js'
import constants from "~/common/constants.js";
import {ElMessage, ElMessageBox} from "element-plus";
import {ArrowDown} from "@element-plus/icons-vue";
import {md5} from 'js-md5'

const conditionState = ref({
  pageIndex: 1,
  pageSize: 10,
  userId: '',
  type: '',
  total: 0,
})


const userList = ref([])
const logList = ref([])

const getAllUserList = () => {
  userList.value = []
  api.getAllUser().then((res) => {
    if (res.data) {
      userList.value = res.data
    }
  })
}

const getOptLogList = () => {
  logList.value = []
  api.getLogList({
    pageIndex: conditionState.value.pageIndex,
    pageSize: conditionState.value.pageSize,
    userId: conditionState.value.userId,
    type: conditionState.value.type
  }).then((res) => {
    if (res.data) {
      logList.value = res.data.data
      conditionState.value.total = res.data.recordTotal
    }
  })
}
const handleSearch = () => {
  conditionState.value.pageIndex = 1
  getOptLogList()
}
const handlePageChange = () => {
  getOptLogList()
}
getAllUserList()
getOptLogList()
</script>

<style scoped lang="scss">
.pagination-box{
  position: relative;
  padding: 0.5rem 0;
  display: flex;
  justify-content: flex-end;
}
</style>
